package com.xpqh.generator;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.fill.Column;
import org.junit.Test;


import java.util.Collections;
import java.util.HashMap;
import java.util.Map;



/**
 * 实体生成
 *
 * @author lizhihui
 * @date 2025.03.21
 */
public class EntityGenerator {
    public static void main(String[] args) {
        System.out.println(System.getProperty("classpath"));
    }

    @Test
    public void entityGenerator() {

        FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/ksg_dev?allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8", "ibao", "maxmac.comIbao2020####")
                .globalConfig(builder -> {
                    builder.author("admin") // 设置作者
                            .outputDir(System.getProperty("user.dir") + "\\src\\main\\java")
                            .dateType(DateType.ONLY_DATE);
                })
                .packageConfig(builder -> {
                    builder.parent("com.xpqh.ksg")
                            .entity("common.persistence.model")
                            .mapper("common.persistence.dao")
                            .service("TTT")
                            .serviceImpl("TTT")
                            .controller("TTT")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, System.getProperty("user.dir") + "\\src\\main\\resources\\mapping")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("ksg_series_details") // 设置需要生成的表名
                            .entityBuilder()
                            .enableLombok()
                            .enableFileOverride()
                            .idType(com.baomidou.mybatisplus.annotation.IdType.AUTO) // 设置主键生成策略
                            .build();
                    builder.mapperBuilder()
                            .enableFileOverride() // 开启 Mapper 接口文件覆盖
                            .build();
                }).execute();
    }
}
